﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using PccCommonForC;
using System.Data.SqlClient;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Collections;
using System.Text;
using System.Collections.Generic;
namespace db_ShowRoom
{
    public class db_user:PccCommonForC.DbBaseObject
    {
         public db_user(): base(){}

        private string strcn;
        private SqlConnection cn;
        public db_user(string mconnect)
        {
            m_ConnectionString = mconnect;
            m_Conn = new SqlConnection(mconnect);
        }

        #region "InsUpd Function"
        //Nguyen Huu Minh
        //20101202
        // db_InsUpd_User
        public string db_InsUpd_User(string strXML)
        {

            PccMsg myMsg = new PccMsg(strXML);
            string user_id = myMsg.Query("user_id").ToString().Trim();
            string name = myMsg.Query("name").ToString().Trim();
            string username = myMsg.Query("username").ToString().Trim();
            string password = myMsg.Query("password").ToString().Trim();
            string ipassword = myMsg.Query("ipassword").ToString().Trim();
            string email = myMsg.Query("email").ToString().Trim();
            string adress = myMsg.Query("adress").ToString().Trim();
            string birthday = myMsg.Query("birthday").ToString().Trim();
            string telephone = myMsg.Query("telephone").ToString().Trim();
            string sex = myMsg.Query("sex").ToString().Trim();
            string company = myMsg.Query("company").ToString().Trim();
            string point = myMsg.Query("point").ToString().Trim();
            string note = myMsg.Query("note").ToString().Trim();
            string city_id = myMsg.Query("city_id").ToString().Trim();
            string dis_id = myMsg.Query("dis_id").ToString().Trim();
            string activeEmail = myMsg.Query("activeEmail").ToString().Trim();
            string emailPass = myMsg.Query("emailPass").ToString().Trim();
            string active = myMsg.Query("active").ToString().Trim();
            string Type = myMsg.Query("Type").ToString().Trim();

            if (user_id == "")
                user_id = "0";
            if (sex == "")
                sex = "0";
            if (point == "")
                point = "0";
            if (city_id == "")
                city_id = "0";
            if (dis_id == "")
                dis_id = "0";

            SqlParameter[] parameters = {
                                            new SqlParameter("@user_id",SqlDbType.Int),
											new SqlParameter("@name",SqlDbType.NVarChar,100),
											new SqlParameter("@username",SqlDbType.NVarChar,50),
                                            new SqlParameter("@password",SqlDbType.NVarChar,50),
											new SqlParameter("@ipassword",SqlDbType.NVarChar,50),
                                            new SqlParameter("@email",SqlDbType.NVarChar,100),
											new SqlParameter("@adress",SqlDbType.NVarChar,100),
                                            new SqlParameter("@birthday",SqlDbType.NChar,14),
											new SqlParameter("@telephone",SqlDbType.NChar,14),
                                            new SqlParameter("@sex",SqlDbType.Int),
                                            new SqlParameter("@company",SqlDbType.NVarChar,100),
                                            new SqlParameter("@point",SqlDbType.Int),
                                            new SqlParameter("@note",SqlDbType.NText),                                           
                                            new SqlParameter("@activeEmail",SqlDbType.Char,1),
                                            new SqlParameter("@emailPass",SqlDbType.NVarChar,150),
                                            new SqlParameter("@active",SqlDbType.Char,1),
                                            new SqlParameter("@Type",SqlDbType.Char,1),                                            
                                            new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};
            parameters[0].Value = Convert.ToInt32(user_id);
            parameters[1].Value = name;
            parameters[2].Value = username;
            parameters[3].Value = EncryptMD5(password);
            parameters[4].Value = EncryptMD5(ipassword);
            parameters[5].Value = email;
            parameters[6].Value = adress;
            parameters[7].Value = birthday;
            parameters[8].Value = telephone;
            parameters[9].Value = sex;
            parameters[10].Value = company;
            parameters[11].Value = point;
            parameters[12].Value = note;    
            parameters[13].Value = activeEmail;
            parameters[14].Value = emailPass;
            parameters[15].Value = active;
            parameters[16].Value = Type;
            parameters[17].Direction = ParameterDirection.Output;


            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_IsUpdUser", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[17].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;

        }

        //InsUpd RoleAdmin
       
        #endregion

        #region Ma Hoa Pass
        public static string EncryptMD5(string cleanString)
        {
            Byte[] clearBytes = null;
            clearBytes = new UnicodeEncoding().GetBytes(cleanString);
            Byte[] hashedBytes = ((HashAlgorithm)CryptoConfig.CreateFromName("MD5")).ComputeHash(clearBytes);
            string hashedText = BitConverter.ToString(hashedBytes);
            return hashedText;
        }
        #endregion

        #region "Get Function User Login"
        public DataSet db_GetUserLogin(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string username = myMsg.Query("username").ToString().Trim();
            string password = myMsg.Query("password").ToString().Trim();
           


            SqlParameter[] parameters = { 
                                            new SqlParameter("@username",SqlDbType.NVarChar,100),
                                            new SqlParameter("@password",SqlDbType.NVarChar,50),
                                        
										};

            parameters[0].Value = username;
            parameters[1].Value = EncryptMD5(password);

            ds = RunProcedure("Pro_GetUserLogin", parameters, "Pro_GetUserLogin");
            return ds;
        }

        public DataSet db_GetUserLoginSess(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string username = myMsg.Query("username").ToString().Trim();


            SqlParameter[] parameters = { 
                                            new SqlParameter("@username",SqlDbType.NVarChar,100)
                                        
										};

            parameters[0].Value = username;

            ds = RunProcedure("Pro_GetUserLoginSess", parameters, "Pro_GetUserLogin");
            return ds;
        }

        public DataSet db_GetUser(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string user_id = myMsg.Query("user_id").ToString().Trim();
            string Type = myMsg.Query("Type").ToString().Trim();

            if (user_id == "")
                user_id = "0";

            SqlParameter[] parameters = { 
                                            new SqlParameter("@user_id",SqlDbType.Int),
                                            new SqlParameter("@Type",SqlDbType.Char,1),
                                        
										};

            parameters[0].Value = user_id;
            parameters[1].Value = Type;

            ds = RunProcedure("Pro_GetUser", parameters, "Pro_GetUserLogin");
            return ds;
        }      
        #endregion

        #region "Customer"
        // insert customer
        public string db_InsUpd_Customer(string strXML)
        {
         
            PccMsg myMsg = new PccMsg(strXML);
            string customer_id = myMsg.Query("customer_id").ToString().Trim();
            string user_id = myMsg.Query("user_id").ToString().Trim();
            string sender = myMsg.Query("sender").ToString().Trim();
            string recipientname = myMsg.Query("recipientname").ToString().Trim();
            string senderaddress = myMsg.Query("senderaddress").ToString().Trim();
            string recipientaddress = myMsg.Query("recipientaddress").ToString().Trim();
            string senderemail = myMsg.Query("senderemail").ToString().Trim();
            string sendertelephone = myMsg.Query("sendertelephone").ToString().Trim();
            string recipienttelephone = myMsg.Query("recipienttelephone").ToString().Trim();
            string sendersex = myMsg.Query("sendersex").ToString().Trim();
            string Type = myMsg.Query("Type").ToString().Trim();
            if (user_id == "")
                user_id = "0";
            if (customer_id == "")
                customer_id = "0";
            SqlParameter[] parameters = {
                                            new SqlParameter("@customer_id",SqlDbType.Int),
                                            new SqlParameter("@user_id",SqlDbType.Int),
											new SqlParameter("@sender",SqlDbType.NVarChar,50),
											new SqlParameter("@recipientname",SqlDbType.NVarChar,50),
                                            new SqlParameter("@senderaddress",SqlDbType.NVarChar,100),
											new SqlParameter("@recipientaddress",SqlDbType.NVarChar,100),
                                            new SqlParameter("@senderemail",SqlDbType.NVarChar,100),
											new SqlParameter("@sendertelephone",SqlDbType.NChar,14),
                                            new SqlParameter("@sendersex",SqlDbType.Int),
                                            new SqlParameter("@recipienttelephone",SqlDbType.NChar,14),
                                            new SqlParameter("@Type",SqlDbType.Char,1),
                                            new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};
            parameters[0].Value = Convert.ToDouble(customer_id);
            parameters[1].Value = Convert.ToDouble(user_id);
            parameters[2].Value = sender;
            parameters[3].Value = recipientname;
            parameters[4].Value = senderaddress;
            parameters[5].Value = recipientaddress;
            parameters[6].Value = senderemail;
            parameters[7].Value = sendertelephone;
            parameters[8].Value = sendersex;
            parameters[9].Value = recipienttelephone;
            parameters[10].Value = Type;
            parameters[11].Direction = ParameterDirection.Output;


            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_InsUpdCutomer", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[10].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;

        }

        // Get Customer ID
        public DataSet db_GetCustomerID(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string user_id = myMsg.Query("user_id").ToString().Trim();
            if (user_id == "")
                user_id = "0";

            SqlParameter[] parameters = { 
                                            new SqlParameter("@user_id",SqlDbType.Int),
                                        
										};

            parameters[0].Value =Convert.ToInt32(user_id);

            ds = RunProcedure("Pro_GetCustomerID", parameters, "Pro_GetCustomerID");
            return ds;
        }      
        // Get thong tin dat hang
        public DataSet db_GetThongTinDH(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string customer_id = myMsg.Query("customer_id").ToString().Trim();
            string Type = myMsg.Query("Type").ToString().Trim();
            if (customer_id == "")
                customer_id = "0";

            SqlParameter[] parameters = { 
                                            new SqlParameter("@customer_id",SqlDbType.Int),
                                            new SqlParameter("@Type",SqlDbType.NChar,1),
                                        
										};

            parameters[0].Value =Convert.ToInt32(customer_id);
            parameters[1].Value = Type;

            ds = RunProcedure("Pro_GetThongTinKH", parameters, "Pro_GetCustomerID");
            return ds;
        }      
        #endregion

        #region "Order"
        public string db_InsUpd_Order(string strXML)
        {

            PccMsg myMsg = new PccMsg(strXML);
            string oder_id = myMsg.Query("oder_id").ToString().Trim();
            string customer_id = myMsg.Query("customer_id").ToString().Trim();
            string product_id = myMsg.Query("product_id").ToString().Trim();
            string number = myMsg.Query("number").ToString().Trim();
            string price = myMsg.Query("price").ToString().Trim();
            string money = myMsg.Query("money").ToString().Trim();
            string summoney = myMsg.Query("summoney").ToString().Trim();
            string request = myMsg.Query("request").ToString().Trim();
            string hinhthucTT = myMsg.Query("hinhthucTT").ToString().Trim();
            string phuongthucGH = myMsg.Query("phuongthucGH").ToString().Trim();

            string xacnhanTT = myMsg.Query("xacnhanTT").ToString().Trim();
            string payment = myMsg.Query("payment").ToString().Trim();
            string giaohang = myMsg.Query("giaohang").ToString().Trim();
            string number_type = myMsg.Query("number_type").ToString().Trim();
            string status = myMsg.Query("status").ToString().Trim();
            string sum_point = myMsg.Query("sum_point").ToString().Trim();
            string Type = myMsg.Query("Type").ToString().Trim();
            if (oder_id == "")
                oder_id = "0";
            if (customer_id == "")
                customer_id = "0";
            if (product_id == "")
                product_id = "0";
            if (number == "")
                number = "0";
            if (price == "")
                price = "0";
            if (money == "")
                money = "0";
            if (summoney == "")
                summoney = "0";
            if (hinhthucTT == "")
                hinhthucTT = "0";
            if (phuongthucGH == "")
                phuongthucGH = "0";
            if (xacnhanTT == "")
                xacnhanTT = "0";
            if (payment == "")
                payment = "0";
            if (giaohang == "")
                giaohang = "0";
            if (number_type == "")
                number_type = "0";
            if (sum_point == "")
                sum_point = "0";
            SqlParameter[] parameters = {
                                            new SqlParameter("@oder_id",SqlDbType.Int),
                                            new SqlParameter("@customer_id",SqlDbType.Int),
                                            new SqlParameter("@product_id",SqlDbType.Int),
                                            new SqlParameter("@number",SqlDbType.Int),
                                            new SqlParameter("@price",SqlDbType.Int),
                                            new SqlParameter("@money",SqlDbType.Int),
                                            new SqlParameter("@summoney",SqlDbType.Int),
                                            new SqlParameter("@request",SqlDbType.NVarChar,500),
                                            new SqlParameter("@hinhthucTT",SqlDbType.Int),
                                            new SqlParameter("@phuongthucGH",SqlDbType.Int),
                                            new SqlParameter("@xacnhanTT",SqlDbType.Int),
                                            new SqlParameter("@payment",SqlDbType.Int),
                                            new SqlParameter("@giaohang",SqlDbType.Int),
                                            new SqlParameter("@number_type",SqlDbType.Int), 
                                            new SqlParameter("@status",SqlDbType.NVarChar,50),
                                            new SqlParameter("@sum_point",SqlDbType.Int), 
                                            new SqlParameter("@Type",SqlDbType.Char,1),
                                            new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};
            parameters[0].Value = Convert.ToDouble(oder_id);
            parameters[1].Value = Convert.ToDouble(customer_id);
            parameters[2].Value = product_id;
            parameters[3].Value = number;
            parameters[4].Value = price;
            parameters[5].Value = money;
            parameters[6].Value = summoney;
            parameters[7].Value = request;
            parameters[8].Value = hinhthucTT;
            parameters[9].Value = phuongthucGH;
            parameters[10].Value = xacnhanTT;
            parameters[11].Value = payment;
            parameters[12].Value = giaohang;
            parameters[13].Value = number_type;
            parameters[14].Value = status;
            parameters[15].Value = sum_point;
            parameters[16].Value = Type;
            parameters[17].Direction = ParameterDirection.Output;


            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_InsUpdOrder", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[17].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;

        }
        #endregion

        #region "City"
        public DataSet db_GetDllCity(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string national_id = myMsg.Query("national_id").ToString().Trim();
            if (national_id == "")
                national_id = "0";

            SqlParameter[] parameters = { 
                                            new SqlParameter("@national_id",SqlDbType.Int)
                                          
                                        
										};

            parameters[0].Value = national_id;

            ds = RunProcedure("Pro_GetddlCity", parameters, "GetddlCity");
            return ds;
        }
        public DataSet db_GetddlDistris(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string city_id = myMsg.Query("city_id").ToString().Trim();
            string dis_id = myMsg.Query("dis_id").ToString().Trim();
            string Type = myMsg.Query("Type").ToString().Trim();
            if (city_id == "")
                city_id = "0";
            if (dis_id == "")
                dis_id = "0";

            SqlParameter[] parameters = { 
                                            new SqlParameter("@city_id",SqlDbType.Int),
                                            new SqlParameter("@dis_id",SqlDbType.Int),
                                             new SqlParameter("@Type",SqlDbType.Char,1)
                                          
                                        
										};

            parameters[0].Value = city_id;
            parameters[1].Value = dis_id;
            parameters[2].Value = Type;

            ds = RunProcedure("Pro_GetddlDistris", parameters, "GetddlDistris");
            return ds;
        }      
        #endregion

        #region "List User"
        public DataSet db_GetListUser(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string Type = myMsg.Query("Type").ToString().Trim();
         

            SqlParameter[] parameters = { 
                                            new SqlParameter("@Type",SqlDbType.Char,1)
                                          
                                        
										};

            parameters[0].Value = Type;

            ds = RunProcedure("Pro_GetListUser", parameters, "GetListUser");
            return ds;
        }
        public DataSet db_GetListUserBySearch(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string email = myMsg.Query("email").ToString().Trim();


            SqlParameter[] parameters = { 
                                            new SqlParameter("@email",SqlDbType.NVarChar,100)
                                          
                                        
										};

            parameters[0].Value = email;

            ds = RunProcedure("Pro_GetListUserBySearch", parameters, "GetListUser");
            return ds;
        }
        #endregion

        #region "Get Point"
        public DataSet db_GetPoint(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string user_id = myMsg.Query("user_id").ToString().Trim();
            string Type = myMsg.Query("Type").ToString().Trim();
            if (user_id == "")
                user_id = "0";

            SqlParameter[] parameters = { 
                                            new SqlParameter("@user_id",SqlDbType.Int),
                                            new SqlParameter("@Type",SqlDbType.Char,1)
                                          
                                        
										};

            parameters[0].Value = user_id;
            parameters[1].Value = Type;

            ds = RunProcedure("Pro_GetPoint", parameters, "Pro_GetPoint");
            return ds;
        }
        #endregion

        #region "dổi quà cho user"
        public string db_InsUpd_Gift_User(string strXML)
        {

            PccMsg myMsg = new PccMsg(strXML);
            string gi_id = myMsg.Query("gi_id").ToString().Trim();
            string user_id = myMsg.Query("user_id").ToString().Trim();
            string productb_id = myMsg.Query("productb_id").ToString().Trim();
            string name = myMsg.Query("name").ToString().Trim();           
            string adress = myMsg.Query("adress").ToString().Trim();
            string phone = myMsg.Query("phone").ToString().Trim();
            string note = myMsg.Query("note").ToString().Trim();
            string ok_mk = myMsg.Query("ok_mk").ToString().Trim();            
            string point = myMsg.Query("point").ToString().Trim();
            string Type = myMsg.Query("Type").ToString().Trim();

            if (gi_id == "")
                gi_id = "0";
            if (user_id == "")
                user_id = "0";
            if (productb_id == "")
                productb_id = "0";
            if (point == "")
                point = "0";
            if (phone == "")
                phone = "0";
            SqlParameter[] parameters = {
                                            new SqlParameter("@gi_id",SqlDbType.Int),
                                            new SqlParameter("@user_id",SqlDbType.Int),
                                            new SqlParameter("@productb_id",SqlDbType.Int),
											new SqlParameter("@name",SqlDbType.NVarChar,50),
											new SqlParameter("@adress",SqlDbType.NVarChar,250),
                                            new SqlParameter("@phone",SqlDbType.Int),
											new SqlParameter("@note",SqlDbType.NVarChar,500),
                                            new SqlParameter("@ok_mk",SqlDbType.Char,1),
                                            new SqlParameter("@point",SqlDbType.Int),
                                            new SqlParameter("@Type",SqlDbType.Char,1),
                                            new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};
            parameters[0].Value = Convert.ToInt32(gi_id);
            parameters[1].Value = user_id;
            parameters[2].Value = productb_id;
            parameters[3].Value = name;
            parameters[4].Value = adress;
            parameters[5].Value = phone;
            parameters[6].Value = note;
            parameters[7].Value = ok_mk;
            parameters[8].Value = point;
            parameters[9].Value = Type;
            parameters[10].Direction = ParameterDirection.Output;


            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_InsUpdGift_User", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[10].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;

        }
        #endregion

        #region "Get Point"
        public DataSet db_GetGiftsByUser(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string gi_id = myMsg.Query("gi_id").ToString().Trim();
            string user_id = myMsg.Query("user_id").ToString().Trim();
            string username = myMsg.Query("username").ToString().Trim();
            string email = myMsg.Query("email").ToString().Trim();
            string add_date = myMsg.Query("add_date").ToString().Trim();
            string ok_mk = myMsg.Query("ok_mk").ToString().Trim();
            string Type = myMsg.Query("Type").ToString().Trim();
            if (gi_id == "")
                gi_id = "0";
            if (user_id == "")
                user_id = "0";
            SqlParameter[] parameters = { 
                                            new SqlParameter("@gi_id",SqlDbType.Int),
                                            new SqlParameter("@user_id",SqlDbType.Int),
                                            new SqlParameter("@username",SqlDbType.NVarChar,50),
                                            new SqlParameter("@email",SqlDbType.NVarChar,100),
                                            new SqlParameter("@add_date",SqlDbType.Char,8),
                                            new SqlParameter("@ok_mk",SqlDbType.Char,1),
                                            new SqlParameter("@Type",SqlDbType.Char,1)
                                          
                                        
										};

            parameters[0].Value = gi_id;
            parameters[1].Value = user_id;
            parameters[2].Value = username;
            parameters[3].Value = email;
            parameters[4].Value = add_date;
            parameters[5].Value = ok_mk;
            parameters[6].Value = Type;

            ds = RunProcedure("Pro_GetGiftsByUser", parameters, "GetGiftsByUser");
            return ds;
        }
        #endregion

        #region "Test_User_Email"
        public string db_Test_User_Email(string strXML)
        {

            PccMsg myMsg = new PccMsg(strXML);

            string user_name = myMsg.Query("user_name").ToString().Trim();
            string email = myMsg.Query("email").ToString().Trim();
            string myType = myMsg.Query("Type").ToString().Trim();
            SqlParameter[] parameters = {                                       
                                            new SqlParameter("@user_name",SqlDbType.NVarChar,100),                                           
                                            new SqlParameter("@email",SqlDbType.NVarChar,100),
                                            new SqlParameter("@Type",SqlDbType.Char,1),
											new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};

            parameters[0].Value = user_name;
            parameters[1].Value = email;
            parameters[2].Value = myType;
            parameters[3].Direction = ParameterDirection.Output;

            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_Test_User_Email", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[3].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;
        }
        #endregion

        #region "Test_User_Pass"
        public DataSet db_GetUserPass(string strXML)
        {
            DataSet ds = new DataSet();
            PccMsg myMsg = new PccMsg(strXML);
            string user_id = myMsg.Query("user_id").ToString().Trim();
            string pass = myMsg.Query("pass").ToString().Trim();
            string Type = myMsg.Query("Type").ToString().Trim();
            if (user_id == "")
                user_id = "0";

            SqlParameter[] parameters = { 
                                            new SqlParameter("@user_id",SqlDbType.Int),
                                            new SqlParameter("@pass",SqlDbType.NVarChar,50),
                                            new SqlParameter("@Type",SqlDbType.Char,1)
                                          
                                        
										};

            parameters[0].Value = user_id;
            parameters[1].Value = EncryptMD5(pass);
            parameters[2].Value = Type;

            ds = RunProcedure("Pro_GetPassCurrent", parameters, "GetPassCurrent");
            return ds;
        }
        #endregion

        #region "update pass"
        public string db_UpdPass(string strXML)
        {

            PccMsg myMsg = new PccMsg(strXML);
            string password_c = myMsg.Query("password_c").ToString().Trim();
            string password = myMsg.Query("password").ToString().Trim();

            SqlParameter[] parameters = { 
                                           
                                            new SqlParameter("@password_c",SqlDbType.NVarChar,100),  
                                             new SqlParameter("@password",SqlDbType.NVarChar,50),                                              
											new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};

            parameters[0].Value = EncryptMD5(password_c);
            parameters[1].Value = EncryptMD5(password);
            parameters[2].Direction = ParameterDirection.Output;

            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_UpdPass", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[2].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;
        }
        #endregion

        #region "Thêm e mail nhận quãng cáo"
        public string db_InsUpdEmailQC(string strXML)
        {

            PccMsg myMsg = new PccMsg(strXML);
            string id = myMsg.Query("id").ToString().Trim();
            string email = myMsg.Query("email").ToString().Trim();
            string active = myMsg.Query("active").ToString().Trim();
            string Type = myMsg.Query("Type").ToString().Trim();

            if (id == "")
                id = "0";
            SqlParameter[] parameters = {
                                            new SqlParameter("@id",SqlDbType.Int),
											new SqlParameter("@email",SqlDbType.NVarChar,50),
                                            new SqlParameter("@active",SqlDbType.Char,1),
                                            new SqlParameter("@Type",SqlDbType.Char,1),
                                            new SqlParameter("@Err",SqlDbType.NVarChar,100)
										};
            parameters[0].Value = Convert.ToInt32(id);
            parameters[1].Value = email;
            parameters[2].Value = active;
            parameters[3].Value = Type;
            parameters[4].Direction = ParameterDirection.Output;


            try
            {
                int iReturn = 0, rowsAffected = 0;
                iReturn = RunProcedure("Pro_InsUpdEmailQC", parameters, ref rowsAffected);

                myMsg.ClearContext();

                myMsg.CreateFirstNode("ReturnValue", iReturn.ToString());
                myMsg.CreateFirstNode("RowsAffected", rowsAffected.ToString());
                myMsg.CreateFirstNode("Err", parameters[4].Value.ToString());
            }
            catch (Exception e)
            {
                myMsg.ClearContext();
                myMsg.CreateFirstNode("Err", e.Message.ToString());
            }

            return myMsg.GetXmlStr;

        }
        #endregion
    }
}
